<?php
require_once 'BaseController.php';
class Admin_SettingsController extends BaseController
{
    public $_email = null;
    public $_role = null;
    protected $_arrParam;
    public function init()
    {
        $this->view->module = $this->_request->getModuleName();
        $this->view->controller = $this->_request->getControllerName();
        $this->view->action = $this->_request->getActionName();
        $this->_arrParam = $this->_request->getParams();
        unset($this->_arrParam['controller']);
        unset($this->_arrParam['action']);
        unset($this->_arrParam['module']);

        Zend_Loader::loadClass('AuthModel');
        Zend_Loader::loadClass('AdminModel');
        Zend_Loader::loadClass('SettingsModel');

        Zend_Loader::loadClass('AuthModel');
        $auth = new AuthModel();
        $this->_email = $auth->getIdentityField('sunnet_email');
        $this->_role = $auth->getIdentityField('role');
    }
    public function indexAction(){
        $this->view->headLink()->appendStylesheet('/templates/admin/css/admin_default.css');
        if($this->_request->isPost()){
            $object = $this->_arrParam;
            $eclick_next = $this->_arrParam['eclick_next'];
            $ModelS = new SettingsModel();
            
            $row = $ModelS->fetchRow("name = 'eclick_next'");
            if($row){
                $ModelS->update(array("status" => $eclick_next),"name = 'eclick_next'");   
            }else{
                $ModelS->insert(array("name"=>"eclick_next","status"=> $eclick_next));
            }
            $this->view->object = $object;
        }else{
            $ModelS = new SettingsModel();
            $row = $ModelS->fetchRow("name = 'eclick_next'");
            $this->view->object = $row['status'];
        }
        
    }
}